function [likel,ssvec,flag_ok,lht]=likelNanNSplits(parest,parvec,parposest,funcmod,Y,trainvec,solveopt,addsol)
% =========================================================================
%% LikelNanNSplits.m
%
% This code estimates the likelihood of a 
% 1) NaN model 
% 2) Without Mixed Frequency 
% 3) Regular, i.e. NO Split in matrices
%
% [GG, RR, CONS, eu, SDX, ZZ, initss, ssvec, flag, ssnames]=feval(funcmod,param,options,addsol);
%
% =========================================================================
%% Initialize parameters
likel=-1e20; flag_ok=0;
parvec(parposest)=parest;
%% Model solution, second sample stored in structure second (second sample)
[G,R,C,eu,SDX,Z,~,ssvec,~]=feval(funcmod,parvec,solveopt,addsol);
if isequal(eu,[1;1])==false
    disp('Indeterminacy'); 
    ssvec=[]; 
    return 
end 
[T,ny]=size(Y);
Y = Y';
%% Initialization
pshat=feval(@lyapunov_symm,G(:,:,addsol.tauVec(1)),...
    R(:,:,addsol.tauVec(1))*(SDX(:,:,addsol.tauVec(1))')*...
    SDX(:,:,addsol.tauVec(1))*(R(:,:,addsol.tauVec(1))'));
shat       = zeros(size(G,1),1);

lht        = zeros(T,1);
Zdim       = zeros(T,1); 
W          = eye(ny);

% Filter
for ii=1:T;
    % Handling of missing observations 
    ytt=Y(:,ii);    
    % Determine W and position of the NAN  
    ind =~isnan(ytt);    
    ytt=ytt(ind);    
    Zdim(ii)=length(ytt); 
    Ztt=W((ind==1),:)*Z(:,:,addsol.tauVec(ii));
    ytt = ytt - Ztt*C(:,addsol.tauVec(ii));    
    [shat,pshat,lht(ii)]=feval(@kf,ytt,Ztt,shat,pshat,...
        G(:,:,addsol.tauVec(ii)),...
        R(:,:,addsol.tauVec(ii))*(SDX(:,:,addsol.tauVec(ii))'));
end

%% Likelihood plus integration constant

lht   = lht(trainvec(1):trainvec(2));
likel = -0.5*length(lht)*log(2*pi)*(sum(Zdim))+sum(lht);
flag_ok=1;

%% End of File
end